//
//  NickNameViewController.m
//  WuJieLive
//
//  Created by 张瀚坤 on 2017/10/26.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "NickNameViewController.h"

@interface NickNameViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameText;

@end

@implementation NickNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

-(void)setNavi
{
    self.title = @"修改昵称";
    [self.rightBtn setTitle:@"保存" forState:(UIControlStateNormal)];
    
}

- (void)setUI
{
    self.nameText.text = self.nickName;
}

-(void)rightBtnAction:(UIButton *)sender
{
    [self.view endEditing:YES];
    if (self.nameText.text.length > 0) {
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        NSDictionary * dict = @{@"token":self.userToken,@"user_name":self.nameText.text};
        [HTTPTool POSTForm:[NSString stringWithFormat:@"%@member/edit-username",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            if (isSuccess) {
                self.nickName = self.nameText.text;
                [self.navigationController popViewControllerAnimated:YES];
            }else
            {
                if ([[responseObject objectForKey:@"data"] isKindOfClass:[NSString class]]) {
                    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:responseObject preferredStyle:(UIAlertControllerStyleAlert)];
                    UIAlertAction * done = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                        
                    }];
                    [alert addAction:done];
                    [self presentViewController:alert animated:YES completion:nil];
                }
            }
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        }];
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
